package com.gragra.sampling.vector.tests;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.MixingCorpus;
import com.gragra.data.MixingCorpusBaseImplementation;
import com.gragra.sampling.vector.BinaryStackedClassesUnitCRPFactory;
import com.gragra.sampling.vector.LimitedClassesUnitCRP;
import com.gragra.sampling.vector.VectorStructure;
import com.gragra.util.StringToInt;
/**
 * 
 * @author Christoph Teichmann
 * 14.10.2013
 */
public class TestBinaryStackedClassesUnitCRP
{
	/**
	 * 
	 */
	private LimitedClassesUnitCRP lcc;
	/**
	 * 
	 */
	private VectorStructure vs1;
	@Before
	public void setUp() throws Exception
	{
		vs1 = new VectorStructure(StringToInt.ensure("Hans"), new double[] {5.0,4.5,7.2,2.1}, new int[][] {{0,0},{1,0},{1,1},{2,3}}, 3);
		BinaryStackedClassesUnitCRPFactory fact = new BinaryStackedClassesUnitCRPFactory(0.1, 0.9, 5, 2);
		MixingCorpus<VectorStructure> corpus = new MixingCorpusBaseImplementation<VectorStructure>();
		corpus.addData(vs1);
		lcc = (LimitedClassesUnitCRP) fact.createNewInstance(corpus);
	}
	@Test
	public void testMakeLogProbPopulationSamplingStructureInt()
	{
		double d = lcc.makeLogProb(vs1, 0);
		assertEquals(d,-23.00770431956108,0.0001);
		lcc.add(vs1, 0);
		assertFalse(d==lcc.makeLogProb(vs1, 0));
		assertEquals(lcc.makeLogProb(vs1, 0),-17.136879169583285,0.0001);
		lcc.remove(vs1, 0);
		assertEquals(d,lcc.makeLogProb(vs1, 0),0.00001);
	}
	@Test
	public void testGetLocalLogLike()
	{
		assertEquals(lcc.getLocalLogLike(null, 0),0.0,0.001);
	}
	@Test
	public void testGetNonLocalLogLike()
	{
		lcc.add(vs1, 0);
		assertEquals(lcc.getNonLocalLogLike(0),-23.00770431956108,0.0001);
		lcc.add(vs1, 0);
		assertEquals(lcc.getNonLocalLogLike(0),-42.16443310283354,0.0001);
	}
}